package com.nut.dao.impl;

import com.nut.dao.OrderDao;
import com.nut.pojo.Order;

import java.util.List;

public class OrderDaoImpl extends BaseDao implements OrderDao {
    @Override
    public int SaveOrder(Order order) {
        String sql = "insert into t_order(`order_id`,`create_time`,`price`,`status`,`user_id`)values(?,?,?,?,?)";
        return update(sql,order.getOrderId(),order.getCreateTime(),order.getPrice(),order.getStatus(),order.getUserId());
    }

    @Override
    public List<Order> queryOrderByUserId(int userId) {
        String sql = "select `order_id` orderId,`create_time` createTime,`price` price,`status`,`user_id` userId from t_order where `user_id` = ?";
        return queryForList(Order.class,sql,userId);
    }

    @Override
    public List<Order> queryOrders() {
        String sql = "select `order_id` orderId,`create_time` createTime,`price` price,`status`,`user_id` userId from t_order ";
        return queryForList(Order.class,sql);
    }

    @Override
    public void updateStatus(int status, String orderId) {
        String sql = "update t_order set status = ? where order_id = ?";
        update(sql,status,orderId);
    }

}
